package com.ruoyi.web.controller.check;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.check.domain.SysEquipment;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.service.ISysEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备信息Controller
 *
 * @author hugh.sun
 * @date 2023-02-22
 */
@RestController
@RequestMapping("/check/equipment")
public class SysEquipmentController extends BaseController
{
    @Autowired
    private ISysEquipmentService sysEquipmentService;

    /**
     * 查询设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysEquipment sysEquipment)
    {
        startPage();
        List<SysEquipment> list = sysEquipmentService.selectSysEquipmentList(sysEquipment);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('check:equipment:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(SysEquipment sysEquipment)
    {
        List<SysEquipment> list = sysEquipmentService.selectSysEquipmentList(sysEquipment);
        return getDataTable(list);
    }


    /**
     * 导出设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:export')")
    @Log(title = "设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysEquipment sysEquipment)
    {
        List<SysEquipment> list = sysEquipmentService.selectSysEquipmentList(sysEquipment);
        ExcelUtil<SysEquipment> util = new ExcelUtil<SysEquipment>(SysEquipment.class);
        util.exportExcel(response, list, "设备信息数据");
    }

    /**
     * 获取设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysEquipmentService.selectSysEquipmentById(id));
    }

    /**
     * 新增设备信息
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:add')")
    @Log(title = "设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysEquipment sysEquipment)
    {
        return toAjax(sysEquipmentService.insertSysEquipment(sysEquipment));
    }

    /**
     * 修改设备信息
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:edit')")
    @Log(title = "设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysEquipment sysEquipment)
    {
        return toAjax(sysEquipmentService.updateSysEquipment(sysEquipment));
    }

    /**
     * 删除设备信息
     */
    @PreAuthorize("@ss.hasPermi('check:equipment:remove')")
    @Log(title = "设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysEquipmentService.deleteSysEquipmentByIds(ids));
    }

}
